if(!isallpay()) {
	var shenhe = true;
	document.querySelector('.spkg').style.display = 'none';
}else{
	var shenhe = false;
};
mui.init({
	preloadPages: [{
		url: 'html/Msg.html',
		id: 'Msg',
		styles: {
			top: configs.headerH,
			bottom: configs.navH
		}
	}, {
		url: 'html/My.html',
		id: 'My',
		styles: {
			top: 0,
			bottom: configs.navH
		}
	},{
		url: 'html/Msg_Chat.html',
		id: 'Msg_Chat'
	},{
		url: 'html/DongTai.html',
		id: 'dongtai',
		styles: {
			top: 0,
			bottom: configs.navH
		}
	}],
	swipeBack: false,
});

var WebId_Blog = mui.preload({
	url: 'html/Personal_Blog.html',
	id: 'Personal_Blog',
	styles: {
		"render": "always",
		"popGesture": "hide",
		"bounce": "none",
		"bounceBackground": "#fff",
		"titleNView": {
			backgroundColor: '#fd698d',
			titleColor: '#ffffff',
			type: 'transparent',
			autoBackButton: true,
			buttons: [{
				color: '#fff',
				'float': 'right',
				fontSize: '24px',
				text: '···',
				onclick: clickButton
			}]
		}
	}
});
var activeTab = 'index';
var WebId_index = plus.webview.currentWebview();
var ui = {
	Settitle: document.querySelector('h1'),
	Setindex: document.getElementById("muicontent"),
	header_left: document.querySelector('.indexleft')
//	header_r:document.getElementById('compile')
}
mui("#nav").on("tap", "a", function() {
	var targetTab = this.getAttribute('id');
	if(targetTab == activeTab) {
		return
	}
	

	var title;
	switch(targetTab) {
		case 'index':
			title = '遇见';
			break;
		case 'zhibo':
			title = '直播';
			break;
		case 'Msg':
			title = '我的消息';
			break;
		default:
			title = '';
			break
	}
	if(targetTab == 'index') {
		ui.Setindex.style.display = "block";
		ui.header_left.style.display = "block";
	}else if(targetTab=='zhibo'){
		mui.openWindow({
			url: 'html/page/zhibo.html',
			id: 'zhibo',
			show:{
		    	aniShow:'fade-in'
		    },
			styles: {
				top: 0,
				bottom: configs.navH
			}
		});
	}else{
		if(activeTab == 'index') {
			ui.Setindex.style.display = "none";
			ui.header_left.style.display = "none";
		}
		plus.webview.show(targetTab,'fade-in',300);
	}
	plus.webview.hide(activeTab,'fade-out',300);
	ui.Settitle.innerHTML = title;
	activeTab = targetTab;
});
ui.header_left.addEventListener('click', function(event) {
	getWeizhi();
})
mui('.huan').on('tap','.huanyipi',function(){
	pullupRefresh();
})
//ui.header_r.addEventListener('click', function(event) {
//	pullupRefresh();
//})
//等待页面加载完毕
WebId_index.addEventListener('rendered', function(e) {
	plus.navigator.closeSplashscreen();
	getWeizhi();
	setTimeout(function(){
		var info = plus.push.getClientInfo();
		clientid = info.clientid;
		mui.getJSON(getApiUrl('http://www.jiaoyou0.cn', 'userdata/clientid'), {'clientid': clientid}, function(rep){})
	},6000)
}, false);

function getWeizhi() {
	ui.header_left.innerHTML = "…";
	setTimeout(function(){
		plus.geolocation.getCurrentPosition(function(p){
			ui.header_left.innerHTML = p.address.city;
		}, function(e){
			mui.toast('获取位置信息失败…');
		} );
	},1000)
}
WebId_index.setStyle({scrollIndicator: 'none'})

var page = 0;
var ParentFrame_Data = {};
var allData = plus.storage.getItem('ParentFrame_Data');
if(allData) {
	ParentFrame_Data = functionclass.shuffle(JSON.parse(allData));
}

var url = getApiUrl('http://www.jiaoyou0.cn', 'userdata/recommend');
var shuaxin = false;
var nowYear = new Date().getFullYear();

Vue.use(VueLazyload, {
	preLoad: 1.3,
	error: 'img/function/lodingerro.png',
	loading: 'img/function/lodings.gif',
	attempt: 1
});
var list = new Vue({
	el: '.mui-content',
	data: {
		items: ParentFrame_Data,
		showhide: true,
		showhide1: false,
		juli: 0
	},
	methods: {
		openBlog: function(ii) {
			openPersonalBlog(this.items[ii]['user_id'], this.items[ii]['headimg'], this.items[ii]['nick_name']);
		},
		otherData: function() {
			Setindex.style.display = "none";
			pullupRefresh()
		}
	},
	filters: {
		getAge: function(year) {
			return nowYear - year;
		},
		julis: function() {
			return (Math.random() * 24).toFixed(1)
		}
	}
});

mui.getJSON(url, {
	'page': page
}, function(rsp) {
	if(rsp.code == 200) {
		list.items = functionclass.shuffle(rsp.data);
		plus.storage.setItem('ParentFrame_Data', JSON.stringify(rsp.data));
	} else if(rsp.code == 201) {
		mui.toast('暂无更多推荐')
	} else {
		mui.toast('出错了，请重试')
	}
})
function pullupRefresh() {
	showWaiting('加载中…');
	setTimeout(function() { 
		list.items = functionclass.shuffle(list.items);
		list.$forceUpdate();
		plus.nativeUI.closeWaiting();
	}, 800)
}

var backButtonPress = 0;
mui.back = function(event) {
	backButtonPress += 1;
	if(backButtonPress > 1) {
		plus.runtime.quit()
	} else {
		plus.nativeUI.toast('再按一次退出应用')
	}
	setTimeout(function() {
		backButtonPress = 0
	}, 1000);
	return false
}